package com.xfgg.cloud;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import com.xfgg.cloud.boot.util.UniqueNameGenerator;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;

/**
 * 启动类
 *
 * @author xfgg
 */
@SpringCloudApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, MultipartAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
@EnableApolloConfig
@ComponentScan(nameGenerator = UniqueNameGenerator.class)
public class CloudApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(CloudApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        //初始化内容
    }

    /**
     * 负载均衡策略
     *
     * @return 请求template
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
